package com.alm.handle.service.impl;

import com.alm.handle.core.domain.entity.SysDevLoginLog;
import com.alm.handle.mapper.SysDevLoginLogMapper;
import com.alm.handle.service.ISysDevLoginLogService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysDevLoginLogServiceImpl implements ISysDevLoginLogService {

    @Resource
    private SysDevLoginLogMapper devLoginLogMapper;

    @Override
    public List<SysDevLoginLog> getDevLoginLog(String devMac, String routerMac) {
        LambdaQueryWrapper<SysDevLoginLog> wrapper = new LambdaQueryWrapper<>();
        if(StringUtils.isNotBlank(devMac)) {
            wrapper.eq(SysDevLoginLog::getDvcId, devMac);
        }
        if(StringUtils.isNotBlank(routerMac)) {
            wrapper.eq(SysDevLoginLog::getRouterMac, routerMac);
        }
        wrapper.orderByDesc(SysDevLoginLog::getLoginTime);
        return devLoginLogMapper.selectList(wrapper);
    }
}
